package com.ymatou.iapi.userservice.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.ByuseridBean;
import com.ymatou.iapi.userservice.parameter.enums.AppSourceEnum;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.resp.SingleuserbriefResp;
import com.ymatou.iapi.userservice.parameter.resp.UserDetailsInfoVoResp;
import com.ymatou.iapi.userservice.service.ByuseridCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.model.Userinfoex;
import com.ymttest.database.sqlwapper.JUserWapper;
/**
*根据userid批量查询用户概要信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Byuserid{
	private static ByuseridBean byuseridBean;
	private static ByuseridCall byuseridCall;
	private static JUserWapper jUserWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据userid批量查询用户概要信息");
	}

	@Before
	public void caseUp() {
		byuseridBean=new ByuseridBean();
		byuseridCall=new ByuseridCall();
		jUserWapper=new JUserWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(byuseridCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Byuserid_001() {
		Logger.start(true,"输入正常用户id,不显示扩展字段,成功");
		try {
			//Userinfo model=jUserWapper.selectTop1Userinfo();
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			byuseridBean.setUserId(uid);
			byuseridBean.setIsGetExInfo(false);
			byuseridCall.setData(byuseridBean);
			byuseridCall.callService();	
			verifyOk(byuseridBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_Byuserid_002() {
		Logger.start(false,"输入不存在的用户id,不显示扩展字段,显示未查询到用户");
		try {
			byuseridBean.setUserId(999999999);
			byuseridBean.setIsGetExInfo(false);
			byuseridCall.setData(byuseridBean);
			byuseridCall.callService();	
			UserDetailsInfoVoResp resp=byuseridCall.getResultData();
			Logger.verifyEquals(true, resp.getSuccess(), "验证Success");
			Logger.verifyEquals(100001, resp.getResponseCode(), "验证ResponseCode");
			Logger.verifyIsContains("未查询到用户", resp.getLastErrorMessage(), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_Byuserid_003() {
		Logger.start(false,"不输入用户id,不显示扩展方法,失败");
		try {
			byuseridBean.setUserId(null);
			byuseridBean.setIsGetExInfo(false);
			byuseridCall.setData(byuseridBean);
			byuseridCall.callService();	
			UserDetailsInfoVoResp resp=byuseridCall.getResultData();
			Logger.verifyEquals(false, resp.getSuccess(), "验证Success");
			Logger.verifyEquals(100, resp.getResponseCode(), "验证ResponseCode");
			Logger.verifyIsContains("userId:userid must gte 1", resp.getLastErrorMessage(), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Byuserid_004() {
		Logger.start(true,"输入正常用户id,显示扩展字段,成功");
		try {
			//Userinfo model=jUserWapper.selectTop1Userinfo();
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			byuseridBean.setUserId(uid);
			byuseridBean.setIsGetExInfo(true);
			byuseridCall.setData(byuseridBean);
			byuseridCall.callService();	
			verifyOk(byuseridBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_Byuserid_005() {
		Logger.start(false,"输入不存在的用户id,显示扩展字段,显示未查询到用户");
		try {
			byuseridBean.setUserId(999999999);
			byuseridBean.setIsGetExInfo(true);
			byuseridCall.setData(byuseridBean);
			byuseridCall.callService();	
			UserDetailsInfoVoResp resp=byuseridCall.getResultData();
			Logger.verifyEquals(true, resp.getSuccess(), "验证Success");
			Logger.verifyEquals(100001, resp.getResponseCode(), "验证ResponseCode");
			Logger.verifyIsContains("未查询到用户", resp.getLastErrorMessage(), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_Byuserid_006() {
		Logger.start(false,"不输入用户id,显示扩展方法,失败");
		try {
			byuseridBean.setUserId(null);
			byuseridBean.setIsGetExInfo(true);
			byuseridCall.setData(byuseridBean);
			byuseridCall.callService();	
			UserDetailsInfoVoResp resp=byuseridCall.getResultData();
			Logger.verifyEquals(false, resp.getSuccess(), "验证Success");
			Logger.verifyEquals(100, resp.getResponseCode(), "验证ResponseCode");
			Logger.verifyIsContains("userId:userid must gte 1", resp.getLastErrorMessage(), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/**
	 * 返回成功
	 * @param model
	 * @param byuseridBean
	 */
	public void verifyOk(ByuseridBean byuseridBean)
	{
	  List<Userinfo> userinfoList= jUserWapper.selectUserinfoByUid(byuseridBean.getUserId());
	  List<Userinfoex> userinfoexList=jUserWapper.selectUserinfoexByUid(byuseridBean.getUserId());
	  UserDetailsInfoVoResp resp=byuseridCall.getResultData();
	  Userinfo userinfo=new Userinfo();
	  Userinfoex userinfoex=new Userinfoex();
	  if(userinfoList.size()>0)
	  {
		  userinfo=userinfoList.get(0);
		 
		  if(userinfo.getIsActivateEmail()==null)
		  {
			  Logger.verifyEquals(false, resp.getResult().isActivateEmail(), "验证activateEmail");
		  }
		  else
		  {
			  Logger.verifyEquals(userinfo.getIsActivateEmail(), resp.getResult().isActivateEmail(), "验证activateEmail");
		  }
		  if(userinfo.getIsSetDualSecurity()==null)
		  {
			  Logger.verifyEquals(false, resp.getResult().isSetDualSecurity(), "验证setDualSecurity");
		  }
		  else
		  {
			  Logger.verifyEquals(userinfo.getIsSetDualSecurity(), resp.getResult().isSetDualSecurity(), "验证setDualSecurity");
		  }
		  Logger.verifyEquals(userinfo.getUserId(), resp.getResult().getUserId(), "验证iUserId");
		  Logger.verifyEquals(userinfo.getLoginId(), resp.getResult().getLoginId(), "验证sLoginId");
		  Logger.verifyEquals(userinfo.getLoginMail(), resp.getResult().getLoginEmail(), "验证sLoginEmail");
		  Logger.verifyEquals(userinfo.getLoginMobile(), resp.getResult().getLoginMobile(), "验证sLoginMobile"); 
		  Logger.verifyEquals(userinfo.getLoginPassword(), resp.getResult().getPassword(), "验证sPassword");
		  Logger.verifyEquals(userinfo.getUserType(), resp.getResult().getUserType().getCode(), "验证iType");
		  if(userinfo.getUserGender()!=null&&userinfo.getUserGender()!=null){
			  Logger.verifyEquals(userinfo.getUserGender(),resp.getResult().getUserGender(), "验证iSex");
		  }
		  Logger.verifyEquals(userinfo.getRegisterTime(), resp.getResult().getRegisterTime(), "验证createtime");
		  if(userinfo.getUserState()!=null&& resp.getResult().getUserState()!=null){
			  Logger.verifyEquals(userinfo.getUserState(), resp.getResult().getUserState(), "验证iAction");
		  }
	  }
	  else
	  {
		  Logger.verifyEquals(true, false, "根据userid没有查到主表数据");
	  }
	  
	  if(byuseridBean.getIsGetExInfo()==true)
	  {
		if(userinfoexList.size()>0)
		 {
		  userinfoex=userinfoexList.get(0);
		  Logger.verifyEquals(userinfoex.getEquimentid(), resp.getResult().getEquimentid(), "验证equimentid");
		  Logger.verifyEquals(userinfoex.getDeviceId(), resp.getResult().getDeviceId(), "验证deviceId");
		 if(userinfoex.getRegSource()==0)
			 Logger.verifyEquals("MainSite", resp.getResult().getRegSource().toString(), "验证iRegSource");
		 else if(userinfoex.getRegSource()==1)
			 Logger.verifyEquals("App", resp.getResult().getRegSource().toString(), "验证iRegSource"); 
		 else if(userinfoex.getRegSource()==2)
			 Logger.verifyEquals("Wap", resp.getResult().getRegSource().toString(), "验证iRegSource"); 
		 else if(userinfoex.getRegSource()==6)
			 Logger.verifyEquals("MatouApp", resp.getResult().getRegSource().toString(), "验证iRegSource"); 
		 else if(userinfoex.getRegSource()==7)
			 Logger.verifyEquals("SellerSite", resp.getResult().getRegSource().toString(), "验证iRegSource"); 
		 
		 if(userinfoex.getChannelSource()==0)
		   Logger.verifyEquals("Other", resp.getResult().getChannelSource().toString(), "验证iChannelSource");
		 else if(userinfoex.getChannelSource()==3)
			   Logger.verifyEquals("Alipay", resp.getResult().getChannelSource().toString(), "验证iChannelSource");
		 else if(userinfoex.getChannelSource()==4)
			   Logger.verifyEquals("QQ", resp.getResult().getChannelSource().toString(), "验证iChannelSource");
		 else if(userinfoex.getChannelSource()==5)
			   Logger.verifyEquals("Weibo", resp.getResult().getChannelSource().toString(), "验证iChannelSource");
		 else if(userinfoex.getChannelSource()==6)
			   Logger.verifyEquals("WeiXin", resp.getResult().getChannelSource().toString(), "验证iChannelSource");

		   Logger.verifyEquals(userinfoex.getVisitLanguage(), resp.getResult().getVisitLan(), "验证iVisitLan");

		  if(userinfoex.getTerminalSource()==0)
		    Logger.verifyEquals("Other", resp.getResult().getTerminalSource().toString(), "验证iTerminalSource");
		  else if(userinfoex.getTerminalSource()==1)
			    Logger.verifyEquals("PC", resp.getResult().getTerminalSource().toString(), "验证iTerminalSource");
		  else if(userinfoex.getTerminalSource()==2)
			    Logger.verifyEquals("IOS", resp.getResult().getTerminalSource().toString(), "验证iTerminalSource");
		  else if(userinfoex.getTerminalSource()==3)
			    Logger.verifyEquals("Android", resp.getResult().getTerminalSource().toString(), "验证iTerminalSource");
		  else if(userinfoex.getTerminalSource()==4)
			    Logger.verifyEquals("IPad", resp.getResult().getTerminalSource().toString(), "验证iTerminalSource");
		  
		  if(userinfoex.getTelephone()!=null && userinfoex.getTelephone()!="")
		  {
			  Logger.verifyEquals(userinfoex.getTelephone(), resp.getResult().getTelphone(), "验证sMobilePhone");
		  }
		  if(userinfoex.getLogoUrl()!=null && userinfoex.getLogoUrl()!="")
		  {
			  Logger.verifyEquals(userinfoex.getLogoUrl(), resp.getResult().getLogoUrl(), "验证sUserLogoUrl");
		  }
		  if(userinfoex.getActivateMobileTime()!=null )
		  {
			  Logger.verifyEquals(userinfoex.getActivateMobileTime(), resp.getResult().getActivateMobileTime(), "验证ActivateMobileTime");
		  }
		  if(userinfoex.getActivateEmailTime()!=null )
		  {
			  Logger.verifyEquals(userinfoex.getActivateEmailTime(), resp.getResult().getActivateEmailTime(), "验证activateEmailTime");
		  }
		  
		  if(userinfoex.getQQ()!=null && userinfoex.getQQ()!="")
		  {
			  Logger.verifyEquals(userinfoex.getQQ(), resp.getResult().getQq(), "验证sQQ");
		  }
		  if(userinfoex.getWang()!=null && userinfoex.getWang()!="")
		  {
			  Logger.verifyEquals(userinfoex.getWang(), resp.getResult().getWang(), "验证getWang");
		  }
		  if(userinfoex.getMsn()!=null && userinfoex.getMsn()!="")
		  {
			  Logger.verifyEquals(userinfoex.getMsn(), resp.getResult().getMsn(), "验证getsMsn");
		  }
		  if(userinfoex.getCountry()!=null && userinfoex.getCountry()!="")
		  {
			  Logger.verifyEquals(userinfoex.getCountry(), resp.getResult().getCountry(), "验证country");
		  }
		  if(userinfoex.getProvince()!=null && userinfoex.getProvince()!="")
		  {
			  Logger.verifyEquals(userinfoex.getProvince(), resp.getResult().getProvince(), "验证Province");
		  }
		  if(userinfoex.getCity()!=null && userinfoex.getCity()!="")
		  {
			  Logger.verifyEquals(userinfoex.getCity(), resp.getResult().getCity(), "验证city");
		  }
		  }
		  else
		  {
			  Logger.verifyEquals(true, false, "根据userid没有查到扩展表数据");
		  }
	  }
	  
	  Logger.verifyEquals(true, resp.getSuccess(), "验证Success");
      Logger.verifyEquals(200, resp.getResponseCode(), "验证ResponseCode");
	}
}